home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 February: Tool Chest / Apple Developer CD Series Tool Chest February 1996 (Apple Computer)(1996).iso / Sample Code / Snippets / Files / stdFilterHacking / stdFilterHacking.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-09  |  3.2 KB  |  123 lines  |  [TEXT/MPS ]

  1. #include <Dialogs.h>
  2. #include <Controls.h>
  3. #include <QuickDraw.h>
  4. #include <Windows.h>
  5. #include <ToolUtils.h>
  6. #include <OSUtils.h>
  7. #include <Menus.h>
  8. #include <Fonts.h>
  9. #include <resources.h>
  10. #include <Sound.h>
  11. #include <Traps.h>
  12. #include <Gestaltequ.h>
  13. #include <Memory.h>
  14. #include <Scrap.h>
  15. #include <TextEdit.h>
  16.  
  17. /* prototypes */
  18. ControlHandle   SnatchHandle(DialogPtr thebox, short theGetItem);
  19. void            ToggleCheckBox(DialogPtr myDialog,short theItem);
  20. pascal     Boolean  filterIt(DialogPtr inputDialog, EventRecord *myDialogEvent, short *theDialogItem);
  21.  
  22.  
  23. enum  {
  24.     /* ok and cancel are already defined in Dialogs.h */
  25.     kMessUpItem = 3,
  26.     kHiliteOK
  27. };
  28. enum  {
  29.  
  30.     kSampleDialog = 128, 
  31.     kMessUpAlert
  32. };
  33.  
  34. ModalFilterUPP gModalFilterUPP;
  35.  
  36. #ifdef powerc
  37.    QDGlobals    qd;
  38. #endif
  39.  
  40. main()
  41. {
  42.     DialogPtr myDialog = nil;                               /* the dialog wee're using */
  43.     short hitItem = 0;                                      /* hitItem for ModalDialog */
  44.  
  45.     /* start up managers */
  46.     InitGraf(&qd.thePort);
  47.     InitFonts();
  48.     InitWindows();
  49.     InitMenus();
  50.     TEInit();
  51.     InitDialogs(nil);
  52.     InitCursor();
  53.     
  54.     /* set up the UPP for the Modal Dialog filter */
  55.     gModalFilterUPP = NewModalFilterProc(filterIt);        
  56.  
  57.     /* get our dialog */
  58.     myDialog = GetNewDialog(kSampleDialog, nil, (WindowPtr)-1);
  59.  
  60.     SetDialogDefaultItem(myDialog, ok);
  61.     SetDialogCancelItem(myDialog, cancel);
  62.     /* dim the OK button initially */
  63.     HiliteControl(SnatchHandle(myDialog,ok),255);
  64.  
  65.     do {
  66.         ModalDialog(gModalFilterUPP, &hitItem);
  67.         if(hitItem == kMessUpItem){
  68.         /* bring up an alert to obscure the OK button */
  69.         Alert(kMessUpAlert,nil);
  70.         }
  71.         else{
  72.         if(hitItem == kHiliteOK)
  73.         ToggleCheckBox(myDialog,kHiliteOK);        
  74.         HiliteControl(SnatchHandle(myDialog,ok),GetControlValue(SnatchHandle(myDialog,hitItem)) ? 0 : 255);
  75.         
  76.         }
  77.     
  78.     }
  79.     while (hitItem != ok && hitItem != cancel);
  80.    
  81.     DisposeDialog(myDialog);
  82.     InitCursor();                                           /* Init to prevent I-beam from hanging around in some circumstances */
  83.  
  84.  
  85. }
  86.  
  87.  
  88. pascal Boolean filterIt(DialogPtr inputDialog, EventRecord *myDialogEvent, short *theDialogItem)
  89. {
  90.    ModalFilterUPP  theModalProc;  /* address of standard filter */
  91.  
  92.  
  93.    if (/* myDialogEvent->what == activateEvt || */myDialogEvent->what == updateEvt) {
  94.    /* reset the state of the button based on my */
  95.    /* check box.  Use whatever conditions you need to determine the  */
  96.    /* correct highlighting */
  97.     HiliteControl(SnatchHandle(inputDialog,ok),GetControlValue(SnatchHandle(inputDialog,kHiliteOK)) ? 0 : 255);
  98.  
  99.     } 
  100. /* You must still call through the standard filter for things to work, of course */
  101.   GetStdFilterProc(&theModalProc);
  102.   return CallModalFilterProc(theModalProc, inputDialog, myDialogEvent, theDialogItem);
  103.  
  104. }
  105.  
  106. ControlHandle SnatchHandle(DialogPtr thebox, short theGetItem)
  107. {
  108.     short itemtype;
  109.     Rect itemrect;
  110.     Handle thandle;
  111.     
  112.     GetDialogItem(thebox, theGetItem, &itemtype, &thandle, &itemrect);
  113.     return((ControlHandle)thandle);
  114. } /* end SnatchHandle */
  115.  
  116.  
  117. void ToggleCheckBox(DialogPtr myDialog,short theItem)
  118. {
  119.  
  120. SetControlValue(SnatchHandle(myDialog,theItem),GetControlValue(SnatchHandle(myDialog,theItem)) ? false:true);
  121. }
  122.  
  123.